<template>
  <div class="head-container clearfix">
    <div class="header-left">
      <showAside :toggle-click="toggleClick" />
    </div>
    <div class="header-right">
      <div class="header-user-con">
        <!-- 全屏显示 -->
        <div class="btn-fullscreen" @click="handleFullScreen">
          <el-tooltip effect="dark" :content="fullscreen ? `取消全屏` : `全屏`" placement="bottom">
            <i class="el-icon-rank"></i>
          </el-tooltip>
        </div>
        <!-- 消息中心 -->
        <div class="btn-bell">
          <el-tooltip
            effect="dark"
            :content="message ? `有${message}条未读消息` : `消息中心`"
            placement="bottom"
          >
            <router-link to="/tabs">
              <i class="el-icon-bell"></i>
            </router-link>
          </el-tooltip>
          <span class="btn-bell-badge" v-if="message"></span>
        </div>
        <!-- 用户名下拉菜单 -->
        <el-dropdown class="avatar-container" trigger="click">
          <div class="avatar-wrapper">
            <img
              src="https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3266090804,66355162&fm=26&gp=0.jpg"
              class="user-avatar"
            />
            {{ username }}
            <i class="el-icon-caret-bottom" />
          </div>
          <el-dropdown-menu slot="dropdown" class="user-dropdown">
            <router-link class="inlineBlock" to="/">
              <el-dropdown-item>回到首页</el-dropdown-item>
            </router-link>
            <el-dropdown-item divided>个人设置</el-dropdown-item>
            <el-dropdown-item divided>
              <span style="display:block;" @click="logout">退出登陆</span>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>
<script>
import showAside from "@/components/showAside.vue"; //引入了一个侧边栏是否折叠的组件
export default {
  // name:'header',
  components: {
    showAside
  },
  data() {
    return {
      fullscreen: false,
      name: "linxin",
      message: 2,
      username: "阿赖啊"
    };
  },
  computed: {
    isCollapse: {
      get: function () {
        return this.$store.state.isCollapse;
      },
      set: function (newValue) {
        this.$store.commit("IS_COLLAPSE", newValue); //提交到vuex
      }
    }
  },
  methods: {
    toggleClick() {
      this.isCollapse = !this.isCollapse;
      
    },
    // 用户名下拉菜单选择事件
    logout() {
      this.$router.push("/login");
    },
    // 全屏事件
    handleFullScreen() {
      let element = document.documentElement;
      if (this.fullscreen) {
        if (document.exitFullscreen) {
          document.exitFullscreen();
        } else if (document.webkitCancelFullScreen) {
          document.webkitCancelFullScreen();
        } else if (document.mozCancelFullScreen) {
          document.mozCancelFullScreen();
        } else if (document.msExitFullscreen) {
          document.msExitFullscreen();
        }
      } else {
        if (element.requestFullscreen) {
          element.requestFullscreen();
        } else if (element.webkitRequestFullScreen) {
          element.webkitRequestFullScreen();
        } else if (element.mozRequestFullScreen) {
          element.mozRequestFullScreen();
        } else if (element.msRequestFullscreen) {
          // IE11
          element.msRequestFullscreen();
        }
      }
      this.fullscreen = !this.fullscreen;
    }
  }
};
</script>
<style>
.head-container {
  height: 50px;
}
.header-left {
  float: left;
  line-height: 50px;
}
.header-right {
  float: right;
  line-height: 50px;
}
.btn-fullscreen {
  margin: 0;
  display: inline-block;
}
.btn-bell {
  display: inline-block;
  padding-left: 10px;
  padding-right: 10px;
}
.clearfix {
  clear: both;
}
.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
}
.avatar-wrapper {
  height: 50px;
  line-height: 50px;
}
</style>
